<template>
  <div>
    <div id="main" class="echartsTest" style="width: 500px; height: 300px; margin-left: 30px"></div>
    <div>
      理由：
      <template>
        <el-select v-model="data" placeholder="请选择">
          <el-option
              v-for="item in type"
              :key="item.id"
              :label="item.name"
              :value="item.id">
          </el-option>
        </el-select>
      </template>
      <br>
      天数：
      <el-input v-model="days"></el-input>
      <br>
      结束时间：
      <div class="block">
        <span class="demonstration">默认</span>
        <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="etime"
            type="datetime"
            placeholder="选择日期时间">
        </el-date-picker>
      </div>
      <br>
    </div>
    <div>
      <el-button @click="send">{{ info }}</el-button>
    </div>

  </div>

</template>

<script>
// @ is an alias to /src
import * as echarts from 'echarts';

export default {
  name: 'HomeView',
  data() {
    return {
      info: "",
      data: "",
      days: "",
      etime: "",
      salaryList:[],
      moneyList:[],
      type: [
        {"id": 1, 'name': "病假"},
        {"id": 2, 'name': "事假"},
      ]

    }
  },
  mounted() {
    // this.echartsTest()
    this.getData()


  },
  methods: {
    getSalary() {
      var uid = localStorage.getItem("uid")
      this.axios.get("echarts?uid=" + uid)
          .then(res => {
            console.log(res)
            this.salaryList = res.data.salary_list
            this.moneyList = res.data.month_list
            console.log(this.moneyList)
            console.log(this.salaryList)
            this.echartsTest()
          })
    },
    send() {
      var uid = localStorage.getItem("uid")
      this.axios.get("send?uid=" + uid + "&data=" + this.data + "&days=" + this.days + "&etime=" + this.etime)
          .then(res => {
            console.log(res)

          })
    },
    getData() {
      var uid = localStorage.getItem("uid")
      var rid = localStorage.getItem("rid")
      this.axios.get("data?uid=" + uid + "&rid=" + rid)
          .then(res => {
            console.log(res)
            this.info = res.data.res[0].resname
            this.getSalary()

          })
    },

    getTest() {
      this.axios.get("test")
          .then(res => {
            console.log(res)
          })
    },
    echartsTest() {
      var chartDom = document.getElementById('main');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        xAxis: {
          type: 'category',
          // data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', 'GGG']
          data: this.moneyList
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            // data: [120, 200, 15000, 80, 70, 110, 130, 400],
            data: this.salaryList,
            type: 'bar'
          }
        ]
      };

      option && myChart.setOption(option);
    },
  }
}
</script>




